#include "BaseLoader.h"
#include "..\Util\FileUtil.h"
#include "..\Util\Utils.h"
#include <iostream>

using namespace std;
using namespace util;

#define SEPARATOR '|'

BaseLoader::BaseLoader(const string &baseConfigFile)
{
	if (FileUtil::fileExists(baseConfigFile))
	{
		ifstream shipFile(baseConfigFile);

		string line;
		while (getline(shipFile, line))
		{
			size_t delimiter = line.find_first_of(SEPARATOR);
			string key = line.substr(0, delimiter);

			delimiter = delimiter+1;
			size_t imageSeparator = line.find_first_of(SEPARATOR, delimiter);
			string imageLeft = line.substr(delimiter, imageSeparator - delimiter);
			string imageRight = line.substr(imageSeparator+1);
			
			cout << "Key: " << key << ". Left: " << imageLeft << " - Right: " << imageRight << endl;

			baseImages.insert(pair<string, pair<string, string> >(Utils::trim(key), pair<string, string>(Utils::trim(imageLeft), Utils::trim(imageRight))));
		}
	}
}

BaseLoader::~BaseLoader(void)
{
}

string BaseLoader::getBaseImage(const std::string &type, BaseOrientation orientation)
{
	if (baseImages.find(type) != baseImages.end())
	{
		return orientation == BL_Right ? baseImages[type].first : baseImages[type].second;
	}
	else return "";
}
